

CXX	:= g++
LD	:= g++
AR	:= ar
CXXFLAGS := -Wall -O2 -Werror
INCLUDES = -I..

TARGET	= test.elf t1.elf

LINKS	= -L.
LIBS	= -lpthread -lglut -lGL -lGLEW 

SOURCES :=
SOURCES += ../tools/logging.cpp
SOURCES += image.cpp

OBJS := $(SOURCES:.cpp=.o)
DEPS := $(SOURCES:.cpp=.d)

ILIBS := jpeg/*.o png/*.o zlib/*.o

all: prebuild $(OBJS) $(ILIBS) $(TARGET)

# $(TARGET): $(OBJS)
# 	@echo Linking $@ ...
# 	$(LD) $(OBJS) $(ILIBS) $(LINKS) $(LIBS) -o$@
# 	@echo -------------------------------------------
# 	@echo done.

%.elf: %.o
	@echo Linking $@ ...
	$(LD) $< $(OBJS) $(LINKS) $(ILIBS) $(LIBS) -o$@
	@echo -------------------------------------------
	@echo done.

.cpp.o:
	@echo Compling $@ ...
	$(CXX) -c $< $(INCLUDES) $(CXXFLAGS)  -o $@
	@echo -------------------------------------------

%.d:%.cpp
	$(CXX) -MM $< $(INCLUDES) $(CXXFLAGS) -o $@

jpeg/*.o:
	make -C jpeg

png/*.o:
	make -C png

zlib/*.o:
	make -C zlib

prebuild:
	#echo -------

include $(DEPS)

clean:
	rm -fr $(OBJS) $(DEPS) readlog.o wincurse.o $(TARGET)
	make -C jpeg clean
	make -C png clean
	make -C zlib clean



